package com.aaa.util;

import com.aaa.entity.cart_order.kwc.CartList;
import com.sun.javafx.collections.MappingChange;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * fileName:计算包装类
 * description:
 * author:zxh
 * createTime:2020/2/14 10:56
 * version:1.0.0
 */
public class CalculatePrice {

    /**
     * 计算支付时的购物车小计与总价
     * @param cartLists
     * @return
     */
    public Map calculateCart(List<CartList> cartLists){
         double aggregate = 0;
        for (CartList cartList : cartLists) {
            if (cartList.getProduct().getOriginal_price()!=0&&cartList.getProduct().getOriginal_price()!=null){
                cartList.setSubtotal(cartList.getQuantity()*cartList.getProduct().getOriginal_price());
            }else {
                cartList.setSubtotal(cartList.getQuantity()*cartList.getProduct().getPrice());
            }
            aggregate=aggregate+cartList.getSubtotal();
        }
        Map map=new HashMap();
        map.put("aggregate",aggregate);
        map.put("cartLists",cartLists);
        //用于购物车全选状态
        map.put("selectAllStatus",false);
        return map;
    }
}
